begintalkscript;

variables;

begintalknode 1;
state = -1;
nextstate = 2;
question = "Thasir";
text1 = "You look ahead of you at a wizard, dressed in tattered robes. He looks slightly relieved that you have come.";

begintalknode 2;
state = 2;
nextstate = 3;
question = "What is your name?";
text1 = "The Wizard looks at you carefully. After a while he replies. _Name? Names mean nothing here. Only death. I am Thasir, Empire Wizard._";

begintalknode 3;
state = 3;
nextstate = -1;
question = "What do you mean?";
text1 = "_You'll find out soon enough._";

begintalknode 4;
state = 2;
nextstate = 4;
question = "What is going on here?";
text1 = "_What's going on here? It's a plague of undead. The things are relentless - and what does the Empire send - worthless good-for-nothing adventurers like you!_";

begintalknode 5;
state = 4;
nextstate = 6;
question = "We are loyal servants of the Empress. You should be more civil!";
text1 = "The Wizard doesn't look impressed. _Are you now? Well, so am I, even though I don't like what the Empire has done out here - nothing!_";

begintalknode 6;
state = 4;
nextstate = 5;
question = "We are from Valorim, from Avernum. We don't care anything about the Empress!";
text1 = "The Wizard looks at you in interest. _Are you now. Well, good for you. I nearly got sent down there, for 'Talking against the Empire'. It was really because I picked sides with a young mage named Erika. And she lost._";

begintalknode 7;
state = 5;
nextstate = 7;
question = "Erika - The Old Archmage?";
text1 = "_Archmage? Her? Well, I suppose she had power, but I never dreamed she would make archmage. Hang on - OLD Archmage?_";

begintalknode 8;
state = 7;
nextstate = 6;
question = "She died, Rentar Ihrno of the Vhanatai killed her, cheated in a fight.";
text1 = "The Wizard sheds a silent tear. _I am sorry to hear that. It must have been a terrible loss for Avernum._";

begintalknode 9;
state = 6;
nextstate = 8;
question = "Could you tell us more about the undead?";
text1 = "_Of-course, no need to waste time talking about who we support. I should tell you about what the situation is._";

begintalknode 10;
state = 8;
nextstate = 12;
question = "What is the current situation?";
text1 = "_There used to be a small farming village near here. When the hordes of undead attacked we were forced to flee to the caves. Slowly the vermin have taken most of the others, so that only I and a few remain._"; 



begintalknode 11;
state = 9;
nextstate = 13;
question = "How do we get there?";
text1 = "To get to the Magical town you have to travel through the valley, which is overrun by undead. They get more powerful as you go along._"; 

begintalknode 16;
state = 13;
nextstate = 10;
question = "Go on...";
text1 = "_There are cliffs at the other sides of the valley, so it is the only way in or out, other than boats. The undead have placed many walls and such in your way, and they have built two towers in the valley, one halfway through, and the other near the end._";

begintalknode 12;
state = 9;
nextstate = 11;
question = "Why do we need to get help?";
text1 = "The wizard looks exasperated. _What did the advertisement for this problem say? Almost definitely get killed by undead, no turning back?_";

begintalknode 13;
state = 11;
nextstate = 10;
question = "No, not really.";
text1 = "_My point exactly. The Empire doesn't know we're trapped here. Nor does Avernum, especially since the cave in cut us off from Upper Avernum. You need to tell them our predicament. No-one else can._";

begintalknode 14;
state = 10;
nextstate = 14;
question = "What do I do?";
text1 = "_You must travel hundreds of miles to the end of this valley, on and on and on. There will be many enemies in your path, and it probably won't be safe to rest often._"; 
code = toggle_quest(1,1);
break;

begintalknode 39;
state = 14;
nextstate = 14;
question = "Anything else I can do as well?";
text1 = "_Yes, find and eliminate the source of the Undead. When you are sure no more will be made, report to me._"; 
code = toggle_quest(8,1);
break;

begintalknode 15;
state = 12;
nextstate = 15;
question = "Go on...";
text1 = "_There is a portal here, that we sent for aid with when the first few skeletons attacked, but it is useless now._ He spits on the ground. _The only way out of the valley is through a portal at the other end, in a magical town construct._";

begintalknode 17;
state = 14;
nextstate = -1;
question = "Many enemies?";
text1 = "_Yes, many enemies! Now if you'll let me continue. You must fight on the go, and pray that you live. Because if you don't, this plague will soon spread out from this valley, and attack the Empire itself!_";

begintalknode 18;
state = 15;
nextstate = 9;
question = "Magical town construct?";
text1 = "_Yes, one of the Magical made towns. The Empire, or Avernum, capture the souls of an entire town, and then they position in places to help adventurers and lost people. You need to go there and ask the Empire to help us._";

begintalknode 19;
state = -1;
nextstate = 20;
question = "Brigand";
text1 = "You see a tall brigand, scars covering his body. He looks at you, and speaks. _Whatta you want?_";

begintalknode 20;
state = 20;
nextstate = 21;
question = "Why are you here? Aren't you a brigand?";
text1= "_I was._ The brigand pulls out a pipe and sucks on it. _Then those damned undead started attacking. Killed most o' me mates, and I had to run here._";

begintalknode 21;
state = 21;
nextstate = -1;
question = "We're sorry about your mates, but we need to know what's going on around here.";
text1 = "The brigand spits at you. _Sorry?_ he laughs mirthlessly. _I don't give a damn if you're sorry. And you wanna know what's going on around here? Talk to the wizard, or the Slith!_ He spits at you again, and turns his back.";

begintalknode 22;
state = -1;
nextstate = 23;
personality = 5;
question = "Ssscccchhhhaahaah";
text1 = "You find yourselves face to face with a legendary Slith Avatar. You draw your blades, uncertain of her loyalties. She just stares at you, unblinking.";

begintalknode 23;
state = 23;
nextstate = 24;
personality = 5;
question = "Sheath your blades.";
text1 = "You sheath your blades and watch the Avatar closely. They have a nasty reputation. _I will not harm you._ she says, smiling.";

begintalknode 24;
state = 24;
nextstate = 25;
personality = 5;
question = "Why should we trust you?";
text1 = "She smiles again. _Why should you not? I mean you no harm. I only wish to talk, and maybe help._";

begintalknode 25;
state = 25;
nextstate = 26;
personality = 5;
question = "How can you help us?";
text1 = "_I have seen things. I can teach. But most importantly, I know what lies ahead of you, if you take this quest, and I also know who created this plague. Are those not useful things?_";

begintalknode 26;
state = 26;
nextstate = 28;
personality = 5;
question = "What lies ahead of us?";
text1 = "_Undead. For roughly the first half of your journey there will be minor undead, like skeletons and zombies. After that..._";

begintalknode 27;
state = 26;
nextstate = 29;
personality = 5;
question = "Who has made this plague?";
text1 = "_I know not their name, but they are a race filled with powerful magic. They also have dangerous weapons. They are thin, with spindly arms and legs, but their appearance is deceiving._";

begintalknode 28;
state = 28;
nextstate = 30;
personality = 5;
question = "After that?";
text1 = "_After that you get to the more dangerous ones. Liches and Vampires, and also alien undead. Undead of a weird race. Be wary of those. Some can cast spells, and others are fearsome warriors._";

begintalknode 29;
state = 29;
nextstate = -1;
personality = 5;
question = "Vahnatai?";
text1 = "_Perhaps - as I said, I do not know their names, only that their leader has built two towers, and she visits them regularly._";

begintalknode 30;
state = 30;
nextstate = 25;
personality = 5;
question = "How fearsome?";
text1 = "_Very dangerous. They carry waved blades, which cut smoothly into the flesh, and the mages cast medium strength spells. But they never go in groups of less than 10, so they swamp you with numbers._ She looks around. _There are wounded. Speack quickly._";

begintalknode 31;
state = -1;
nextstate = 32;
question = "Harry the Woodcutter";
text1 = "You come face to face with one of the valley's woodcutters. He looks at you with something akin to reverence.";

begintalknode 32;
state = 32;
nextstate = -1;
question = "What's the lay of the land around here?";
text1 = "_The Lay of the Land? Well, that's a hard one. You see, no-one's actually mapped out the area, and I myself have stayed very close to town._";
text2 = "_I honestly don't know much, all I know is that quite a few miles down the valley, there was a farm. Near that farm was the secret entrance to the..._";
text3 = "He looks startled. _I didn't mean to tell you that. You forget that! You Forget that._ he sighs. _Oh, yes, and there was also another secret passage. Ask Alfonso the Guard._";
text4 = "_And that's all I know, sorry._ the woodcutter looks as if he is actually sorry.";

begintalknode 33;
state = -1;
nextstate = 33;
question = "Refugee";
text1 = "You see one of the many refugees around here.";

begintalknode 34;
state = 33;
nextstate = -1;
question = "Question the refugee";
text1 = "You question the refugee for the next few minutes, shocked by the horrific tale they have to tell. Unfortunately, they tell you nothing of importance.";

begintalknode 35;
state = -1;
nextstate = 36;
question = "Guard";
text1 = "You see the only guard around, looking around with large wide jerks of his head. When you approach he points a weapon in your direction.";
text3 = "When he sees you aren't dead, he relaxes slightly.";

begintalknode 36;
state = 36;
nextstate = 37;
question = "Why are you so nervous?";
text1 = "_The dead. They come in everywhere. We always have at least one penned in somewhere, but it's not good!_";

begintalknode 37;
state = 37;
condition = get_flag(25,15) == 0);
nextstate = -1;
question = "Do you want me to kill it for you?";
text1 = "The guard looks relieved. _If you would. It's stuck between the two storerooms. There's secret doors inside the storerooms to get there. If you kill it, anything in the room is yours!_";
code = toggle_quest(0,1);
break;

begintalknode 38;
state = -1;
nextstate = 39;
question = "Priest";
text1 = "You walk towards one of the cave's priests. She turns a haggard looking face towards you.";

begintalknode 39;
state = 39;
nextstate = -1;
question = "Question the Priest";
text1 = "You make small talk with the priest, but learn nothing. She is soon called away to tend to the injured.";

//begintalknode 40;
//state = 36;
//nextstate = 37;
//condition = get_flag(25,15) < 1;
//question = "What's your name?";
//text1 = "_Alfonso, Alfonso del Carmal. I'm the only Guard left._ The Guard says, while glancing around nervously.";
//text3 = "You ask him why he is nervous.";
//text5 = "_One of the undead broke in yesterday. A nasty creature that. We haven't managed to kill it yet. It's already taken some of our number.";

begintalknode 40;
state = 36;
nextstate = -1;
condition = get_flag(25,15) == 1);
question = "I have killed the undead beast as you requested.";
text1 = "The guard looks pleased. _Good, we can all rest a lot better now. Thank you for this. As I promised, all in that room is yours._";
code = toggle_quest(0,0);
toggle_quest(6,1);
set_flag(25,15,2);
break;
            

begintalknode 41;
state = 25;
nextstate = 42;
personality = 5;
personality = 5;
condition = (get_flag(25,20) > 0);
question = "Why do you want to do this?";
text1 = "_Because I do. I also need your help._";



begintalknode 42;
state = 25;
nextstate = -1;
personality = 5;
question = "How can we help?";
text1 = "_One of my friends lives on a Farm further down the valley. I would like someone to check if he is still alive._";
text3 = "She smiles, _I will reward you handsomely if you do this. I will make you all far stronger. My powers are infinite!_";
code = toggle_quest(2,1);
       set_flag(25,20,2);
       break;

begintalknode 47;
state = 25;
nextstate = -1;
personality = 5;
condition = (get_flag(5,1) == 1);
question = "We've been to your friend's farm. There was no-one left alive.";
text1 = "_I was afraid of that. But thank you for checking. You will be wanting your reward - I guess?_ You nod a yes. _Here it is._";
text3 = "She waves an arm over you, and you feel a lot wiser.";
code = 
toggle_quest(2,0);
toggle_quest(5,1); 
award_party_xp(2500,25);
break;
              
begintalknode 43;
state = 26;
personality = 5;
nextstate = -1;
question = "I can teach much spellcraft.";
text1 = "_I can teach no more._";
code = begin_shop_mode("Avatar's Spells","The Avatar knows a great many mage and priest spells. Fortunately, you can get them VERY cheaply.",7,0,6);
break;

begintalknode 44;
state = 37;
condition = get_flag(25,15) == 2);
nextstate = -1;
question = "Do you want me to kill it for you?";
text1 = "_No need, thankfully you've already done that. We are all extremely grateful to you about that. If you want, I can tell you a bit about the land around.";
code = set_flag(25,15,3);
break;

begintalknode 45;
state = 37;
condition = get_flag(25,15) == 3);
nextstate = -1;
question = "Yes Please. What do you know?";
text1 = "Alfonso smiles, a weak smile at best, _Well, the Undead have erected a wall just before the first bridge of the river, the one closest to here. ";
text2 = "To get past THAT, you have two choices. You can either fight past them, though you would probably need at least a level 35 party.";
text3 = "OR, you can skip that wall, by using a secret network of passages inside the hill. You can do that by trying to enter the hill near the Wall.";
text4 = "However, it might be wiser if you kill the undead in the wall, even if you go in the back entrance, since the front is trapped.";
text5 = "The leader there is a bladesmaster, and is sure to have a bladesmaster sword. After that, you should have no trouble reaching the Tower.";
text6 = "If you are injured, or just need a safe place, there is a supply depot in the hills, guarded by invisible guardians, against the Undead.";
text7 = "There, you will find basic alchemy ingredients, as well as lots of bread. Also, they have patrols up to the first tower, but I have no clue of what goes on inside.";
text8 = "The only thing we do know, is that a being called Rentar-Ihrno is still alive, and commanding the Undead._ Alfonso stops, and you thank him for his time.";
code = set_flag(25,15,4);
break;

begintalknode 46;
state = 36;
condition = get_flag(25,15) == 4);
nextstate = -1;
question = "We would like to hear of the terrain again.";
text1 = "Alfonso sighs, and repeats himself, watching nervously around. _As you know, the Undead have erected a wall just before the bridge.";
text2 = "To get past THAT, you can do two things. You can either fight past them, though you would probably need at least a level 35 party.";
text3 = "OR, you can skip that wall, by using a secret network of passages inside the hill. You can do that by trying to enter all of the walls near the Wall.";
text4 = "However, it might be wiser if you kill the undead in the wall, even if you go in the back entrance, since the front is trapped.";
text5 = "The leader there is a bladesmaster, and is sure to have a bladesmaster sword. After that, you should have no trouble reaching the Tower.";
text6 = "If you are injured, or just need a safe place, there is a supply depot in the hills, guarded by invisible guardians, against the Undead.";
text7 = "There, you will find basic alchemy ingredients, as well as lots of bread. Also, they have patrols up to the first tower, but I have no clue of what goes on inside.";
text8 = "The only thing we do know, is that a being called Rentar-Ihrno is still alive, and commanding the Undead._ You thank Alfonso for his time, once more.";